package main

import (
	"container/list"
	"fmt"
)

//原生的遍历
func TraverseList(lst *list.List) {
	head := lst.Front()
	for head.Next() != nil {
		fmt.Printf("%v", head.Value)
		head = head.Next()
	}
	fmt.Println()
}

func ReverseList(lst *list.List) {
	tail := lst.Back()
	for tail.Prev() != nil {
		fmt.Printf("%v", tail.Value)
		tail = tail.Prev()
	}
	fmt.Println()
}

func main() {
	lst := list.New()
	lst.PushBack(1)
	lst.PushBack(2)
	lst.PushBack(3)
	lst.PushBack(4)
	lst.PushBack(5)
	lst.PushBack(6)
	lst.PushBack(7)
	lst.PushBack(8)
	//正着遍历
	TraverseList(lst)
	//反着遍历
	ReverseList(lst)
	//直接将尾元素直接删掉
	lst.Remove(lst.Back())
}
